package com.dushibao.manage.article;

import com.dushibao.service.ArticleService;
import com.dushibao.service.impl.ArticleServiceImpl;
import com.dushibao.utils.Page;
import com.dushibao.view.ModelAndView;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/website/article/list")
public class ListServlet extends HttpServlet {
    ArticleService articleService = new ArticleServiceImpl();

    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        String current = req.getParameter("current");
        String pageSize = req.getParameter("pageSize");
        String author = req.getParameter("author");
        String title = req.getParameter("title");

        Page page = new Page();
        page.setCurrent(Integer.parseInt(current==null?"1":current));
        page.setPageSize(Integer.parseInt(pageSize==null?"10":pageSize));

        Page iPage = articleService.page(page,author,title);

        Map<String,Object> maps = new HashMap<>();
        maps.put("iPage",iPage);
        maps.put("author",author);
        maps.put("title",title);


        ModelAndView mv = new ModelAndView("website/article/list",maps);
    }
}
